package leetCode.offer27;


/**
 * 请完成一个函数，输入一个二叉树，该函数输出它的镜像。
 */
public class Solution1 implements Solution {


    @Override
    public TreeNode mirrorTree(TreeNode root) {
        if(root==null) return null;
        TreeNode result = new TreeNode(root.val);
        rightToLeft(root,result);

        return result;
    }


    public static void rightToLeft(TreeNode root,TreeNode target){
        if(root==null){
            return;
        }
        if(root.right!=null){
            target.left = new TreeNode(root.right.val);
        }
        if(root.left!=null){
            target.right = new TreeNode(root.left.val);
        }
        rightToLeft(root.right,target.left);
        rightToLeft(root.left,target.right);
    }


}
